<?php
declare (strict_types=1);

namespace app\client\controller\say;

use app\common\controller\Frontend;
use app\common\model\banxi\say\SayGrade as SayGradeModel;
use think\db\exception\DbException;

class Grade extends Frontend
{
    protected array $noNeedLogin = [];
    protected array $noNeedPermission = [];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new SayGradeModel();
    }


    /**
     * 分页查询
     * @return void
     * @throws DbException
     */
    public function listGradePage(): void
    {
        $param = $this->request->param(['index', 'limit', 'orderBy', "query"]);
        //查询条件解析
        $where = get_query($param);
        //获取分页数据
        $pageParams = get_page_params($param);
        $list = $this->model->getListPage($where, $pageParams['page'], $pageParams['limit']);
        $this->ok('操作成功', result_row($list));
    }

    public function listGrade(): void
    {
        $param = $this->request->param(["query"]);
        //查询条件解析
        $where = get_query($param);
        $list = $this->model->with([
            'categoryInfo' => function ($query) {
                $query->field('id,name');
            }])->where($where)
            ->order(['sortNum' => 'asc'])
            ->withoutField('basicScore,suggest,wordSuggest,key')
            ->select();
        $this->ok('操作成功', $list);
    }

}
